package com.example.task.sqlite.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.task.bean.Recode;
import com.example.task.bean.Teacher;
import com.example.task.bean.User;
import com.example.task.sqlite.DBHelper;

import java.util.ArrayList;
import java.util.List;

public class RecodeDao {
    private DBHelper dbHelper;

    public RecodeDao(Context context) {
        this.dbHelper = new DBHelper(context);
    }

    public void add(Recode recode){
        ContentValues contentValues = new ContentValues();
        contentValues.put("data", recode.getData());

        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.insert("recode", null, contentValues);
    }
    public void delete(){
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.execSQL("DELETE FROM recode");
    }
    public List<Recode> select(){
        String sql = "select * from recode";

        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cursor = db.rawQuery(sql, null);

        List<Recode> list = new ArrayList();
        for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
            String idrecode = cursor.getString(cursor.getColumnIndex("idrecode"));
            String data = cursor.getString(cursor.getColumnIndex("data"));

            Recode recode = new Recode();
            recode.setIdrecode(idrecode);
            recode.setData(data);
            list.add(recode);
        }

        Log.i("query",list.toString());
        return list;
    }
}
